package web.Data;

import service.User_Service;
import service.impl.User_ServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateWarningServlet")
public class UpdateWarningServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置页面编码
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");

        String IMEI = request.getParameter("IMEI");
        int type = Integer.parseInt(request.getParameter("type"));

        //调用service更新
        User_Service user_service = new User_ServiceImpl();
        if (user_service.updateWarning(IMEI))
        {
            /*重定向*/
            if (type==1)
            {
                response.sendRedirect("upWarningServlet");
            }else if(type==2)
            {
                response.sendRedirect("editorUpServlet");
            }

        }
        else
        {
            request.setAttribute("delError","删除失败");
            /*重定向*/
            if (type==1)
            {
                request.getRequestDispatcher("upWarningServlet").forward(request,response);
            }else if(type==2)
            {
                request.getRequestDispatcher("editorUpServlet").forward(request,response);
            }

        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
